package org.example.elm_xiangmu.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.example.elm_xiangmu.po.User;
import org.example.elm_xiangmu.result.Result;
import org.example.elm_xiangmu.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@CrossOrigin
@RestController
@RequestMapping("/User")
@Tag(name = "用户")
public class UserController {
    @Autowired
    UserService userService;

    @Operation(summary = "根据用户编号与密码查询用户信息")
    @GetMapping("/getUserByIdByPass")
    public Result getUserByIdByPass(@Parameter(description = "用户编号") @RequestParam String userId,
                                @Parameter(description = "密码") @RequestParam String password) {

        return userService.getUserByIdByPass(userId,password);

    }

    @Operation(summary = "根据用户编号查询用户表返回的行数")
    @GetMapping("/getUserById")
    public Result getUserById(@Parameter(description = "用户编号") @RequestParam String userId) {

        return userService.getUserById(userId);

    }

    @Operation(summary = "向用户表中添加一条记录")
    @PostMapping("/saveUser")
    public Result saveUser(@Parameter(description = "用户编号") @RequestParam String userId,
                           @Parameter(description = "密码") @RequestParam String password,
                           @Parameter(description = "用户名称") @RequestParam String userName,
                           @Parameter(description = "用户性别") @RequestParam String userSex) {
        User user = new User();
        user.setUserId(userId);
        user.setPassword(password);
        user.setUserName(userName);
        user.setUserSex(userSex);
        return userService.saveUser(user);

    }



}
